package com.ggh.jinjilive.ui.mine;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.BarUtils;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityMineLevelBinding;
import com.ggh.jinjilive.listener.AddOnClickListener1;
import com.ggh.jinjilive.mobile.mine.LevelMobile;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.ui.mine.adapter.MineLevelAdapter;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.ggh.jinjilive.utils.GeneralUtils;
import com.gyf.immersionbar.ImmersionBar;

import java.util.List;


@Route(path = ARouterUtils.MineLevelActivity)
public class MineLevelActivity extends BaseActivity<ActivityMineLevelBinding> implements View.OnClickListener {
    //适配器
    private MineLevelAdapter mineLevelAdapter;
    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).keyboardEnable(true).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_mine_level;
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("我的等级",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
    }

    @Override
    public void initData() {
        super.initData();
        mineLevelAdapter = new MineLevelAdapter();
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        binding.rv.setLayoutManager(layoutManager);
        binding.rv.setAdapter(mineLevelAdapter);



        binding.userButton.setTextColor(Color.parseColor("#1890ff"));
        binding.hostButton.setTextColor(Color.parseColor("#FFFFFF"));
        //用户等级
        GeneralUtils.authMyanchorlevel(new AddOnClickListener1() {
            @Override
            public void onSkipClicked(Object mObject) {
                LevelMobile levelMobile = (LevelMobile) mObject;
                if(null != levelMobile){
                    //等级信息
                    setLevel(levelMobile);
                    //\级别列表
                    GeneralUtils.otherUserlevellist(new AddOnClickListener1() {
                        @Override
                        public void onSkipClicked(Object mObject) {
                            List<LevelMobile> levelMobileList = (List<LevelMobile>) mObject;
                            if(null != levelMobileList && levelMobileList.size() > 0){
                                mineLevelAdapter.setAdd(levelMobileList);
                            }
                        }
                    });
                }
            }
        });
    }


    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //用户等级
        binding.userButton.setOnClickListener(this);
        //主播等级
        binding.hostButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.user_Button://用户等级
                binding.userButton.setTextColor(Color.parseColor("#1890ff"));
                binding.hostButton.setTextColor(Color.parseColor("#FFFFFF"));
                GeneralUtils.authMyanchorlevel(new AddOnClickListener1() {
                    @Override
                    public void onSkipClicked(Object mObject) {
                        LevelMobile levelMobile = (LevelMobile) mObject;
                        if(null != levelMobile){
                            //等级信息
                            setLevel(levelMobile);
                            //\级别列表
                            GeneralUtils.otherUserlevellist(new AddOnClickListener1() {
                                @Override
                                public void onSkipClicked(Object mObject) {
                                    List<LevelMobile> levelMobileList = (List<LevelMobile>) mObject;
                                    if(null != levelMobileList && levelMobileList.size() > 0){
                                        mineLevelAdapter.setAdd(levelMobileList);
                                    }
                                }
                            });
                        }
                    }
                });
                break;
            case R.id.host_Button://主播等级
                binding.userButton.setTextColor(Color.parseColor("#FFFFFF"));
                binding.hostButton.setTextColor(Color.parseColor("#1890ff"));
                GeneralUtils.authMyuserlevel(new AddOnClickListener1() {
                    @Override
                    public void onSkipClicked(Object mObject) {
                        LevelMobile levelMobile = (LevelMobile) mObject;
                        if(null != levelMobile){
                            //等级信息
                            setLevel(levelMobile);
                            //主播等级列表
                            GeneralUtils.otherAnchorlevellist(new AddOnClickListener1() {
                                @Override
                                public void onSkipClicked(Object mObject) {
                                    List<LevelMobile> levelMobileList = (List<LevelMobile>) mObject;
                                    if(null != levelMobileList && levelMobileList.size() > 0){
                                        mineLevelAdapter.setAdd(levelMobileList);
                                    }
                                }
                            });
                        }
                    }
                });
                break;
        }
    }



    /**
     * 等级信息
     * @param levelMobile
     */
    private void setLevel(LevelMobile levelMobile){
        //头像
        Glide.with(binding.RoundedImageView).load(levelMobile.getHead_portrait()).into(binding.RoundedImageView);
        //等级
        binding.tvLevelName.setText("LV." + levelMobile.getLevel());
        //经验值
        binding.gradeMainLefttext.setText("经验值:" + levelMobile.getExperience_value());
        //距离升级
        binding.gradeMainRighttext.setText("距离升级:" + (levelMobile.getEnd_value() - levelMobile.getExperience_value()));
        //等级
        binding.gradeMineLeftGrade.setText("LV." + levelMobile.getLevel());
        //进度
        binding.progressbarUpdown.setMax(levelMobile.getEnd_value());
        binding.progressbarUpdown.setProgress(levelMobile.getExperience_value());
        //等级
        binding.gradeMineRightGrade.setText("LV." + levelMobile.getThe_level_name());
    }
}
